/**
 * 
 */
package com.wm.service.imp;

import java.util.List;

import com.wm.bean.City;
import com.wm.dao.CityDAO;
import com.wm.service.CityService;
import com.wm.service.web.PageList;
import com.wm.service.web.Pages;

/**
 * @author zhangbaochao
 *
 */
public class CityServiceImp implements CityService {
	
	private CityDAO cityDAO;

	public CityDAO getCityDAO() {
		return cityDAO;
	}


	public void setCityDAO(CityDAO cityDAO) {
		this.cityDAO = cityDAO;
	}
	
	/**
	 * 保存City对象
	 * 
	 * @param city
	 * 			City
	 * @return City
	 * 			City
	 */
	public City saveCity(City city){
		return this.getCityDAO().saveCity(city);
	}
	
	/**
	 * 更新City对象
	 * 
	 * @param city
	 * 			City
	 * @return City
	 * 			City
	 */
	public City updateCity(City city){
		return this.getCityDAO().updateCity(city);
	}
	
	/**
	 * 根据ID删除City对象
	 * 
	 * @param id
	 * 			long
	 */
	public void removeCityById(long id){
		this.getCityDAO().removeCityById(id);
	}
	
	/**
	 * 根据ID获取City对象
	 * 
	 * @param id
	 * 			long
	 * @return City
	 * 			City
	 */
	public City findCityById(long id){
		return this.getCityDAO().findCityById(id);
	}
	
	/**
	 * 根据参数获取City对象列表
	 * 
	 * @param isShow
	 * 			int
	 * @param orderby
	 * @param ascOrDesc
	 * @return List
	 * 			List
	 */
	public List findCitysByIsShow(int isShow,String orderby,int ascOrDesc){
		return this.getCityDAO().findCitysByIsShow(isShow, orderby, ascOrDesc);
	}


	/**
	 * 根据参数获取City对象列表
	 * 
	 * @param isShow
	 * 			int
	 * @param orderby
	 * @param ascOrDesc
	 * @param pages
	 * @return PageList
	 * 			PageList
	 */
	public PageList findCitysByIsShow(int isShow,String orderby,int ascOrDesc,Pages pages){
		PageList pl = new PageList();
        if (pages.getTotalNum() == -1) {
            pages.setTotalNum(this.getCityDAO().getCityNumByIsShow(isShow));
        }
        pages.executeCount();
        if(pages.getTotalNum() == 0){
        	pl.setObjectList(null);
        	pl.setPages(pages);
        	return pl;
        }
        List l = this.getCityDAO().findCitysByIsShow(isShow, orderby, ascOrDesc, pages.getSpage(), pages.getPerPageNum());
        if(l == null || l.isEmpty()){
	   		 pl.setObjectList(null);
	   	     pl.setPages(pages);
	   		 return pl;
		}else{
			pl.setObjectList(l);
	        pl.setPages(pages);
	        return pl;
		}  
	}

}
